<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="企业简称" prop="abbreviation">
        <el-input v-model="queryParams.abbreviation" placeholder="请输入企业简称" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="企业名称" prop="name" label-width="120px">
        <el-input v-model="queryParams.name" placeholder="请输入企业名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['org:building:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['org:building:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['org:building:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['org:building:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" />
    </el-row> -->
    <!-- @selection-change="handleSelectionChange" -->
    <el-table v-loading="loading" :data="buildingList">
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <el-table-column label="序号" align="center" type="index" />
      <el-table-column label="企业简称" align="center" prop="abbreviation" />
      <el-table-column label="企业名称" align="center" prop="name" />
      <el-table-column label="企业详细地址" align="center" prop="address" />
      <el-table-column label="企业联系人" align="center" prop="contactPerson" />
      <el-table-column label="成立时间" align="center" prop="establishmentTime" />
      <el-table-column label="所属行业" align="center" prop="industry">
        <template slot-scope="scope">
          {{ scope.row.industry | dynamicText(industryOptions) }}
        </template>
      </el-table-column>
      <el-table-column label="公司logo" align="center" prop="logo">
        <template slot-scope="scope">
          <el-avatar icon="el-icon-user-solid" size="small" style="margin-right: 0.5rem;"
            :src="getUrl(scope.row.logo)"></el-avatar>
        </template>
      </el-table-column>
      <el-table-column label="地图标点详细地址" align="center" prop="mapAddress" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row.id)"
            v-hasPermi="['org:building:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-more" @click="handleDetail(scope.row.id)"
            v-hasPermi="['org:building:list']">详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
    <Form v-if="formVisible" ref="Form" @refreshList="refreshList" />
    <Detail v-if="detailVisible" ref="Detail" @refreshList="refreshList" />
  </div>
</template>

<script>
import {
  delBuilding,
  addBuilding,
  updateBuilding,
} from "@/api/system/building";
import { enterpriseList } from "@/api/enterprise/index";
import Form from "./form.vue";
import Detail from './detail.vue'
import { getDicts as getDicts } from '@/api/system/dict/data'

export default {
  name: "Building",
  components: { Form, Detail },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 委托单位列表
      userList: [],
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 建筑表格数据
      buildingList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 修改页面
      formVisible: false,
      detailVisible: false,
      // 编辑楼层
      editFloorVisible: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        abbreviation: null,
        name: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      enterpriseIndustryList: [],
      industryOptions: []

    };
  },
  created() {
    this.getList();
  },
  mounted() {

  },
  methods: {
    /** 查询建筑列表 */
    getList() {
      this.loading = true;
      enterpriseList(this.queryParams).then((response) => {
        this.buildingList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
      // 获取行业
      getDicts('enterprise_industry').then(res => {
        let arr = []
        for (let i = 0; i < res.data.length; i++) {
          arr.push({
            id: res.data[i].dictValue,
            fullName: res.data[i].dictLabel
          })
        }
        this.industryOptions = arr
      })
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        serviceOrgId: null,
        customerId: null,
        name: null,
        address: null,
        pointPositionDesc: null,
        abovegroundNumber: null,
        undergroundNumber: null,
        longitude: null,
        latitude: null,
        invalid: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    // 跳转详情
    handleDetail(id) {
      this.detailVisible = true;
      this.$nextTick(() => {
        this.$refs.Detail.init(id);
      });
    },
    getUrl(url) {
      return process.env.VUE_APP_WEBSC_API + url
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加建筑";
    },
    /** 修改按钮操作 */
    handleUpdate(id) {
      this.formVisible = true
      this.$nextTick(() => {
        this.$refs.Form.init(id)
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateBuilding(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBuilding(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除建筑编号为"' + ids + '"的数据项？')
        .then(function () {
          return delBuilding(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "/manager/building/export",
        {
          ...this.queryParams,
        },
        `building_${new Date().getTime()}.xlsx`
      );
    },

    refreshList(isrRefresh, index) {
      this.formVisible = false
      if (isrRefresh) this.getList()
    },
  },
};
</script>
<style lang="scss" scoped>
.mapSty {
  width: 100%;
  height: 450px;
  position: relative;
}

#allMap {
  width: 100%;
  height: 450px;
}
</style>